import Phaser from 'phaser'
import Configer from '../types/configer';


export default class MapTest extends Phaser.Scene {
    private playerMain!: Phaser.GameObjects.Sprite;
    private cursors!: Phaser.Types.Input.Keyboard.CursorKeys;
    private tian!: Phaser.GameObjects.Container;
    constructor() {
        super('MapTest');
    }

    create() {
        /***
         * 3000 * 1000
         */

        let gameWidth = <number>this.sys.game.config.width;
        let gameHeight = <number>this.sys.game.config.height;
        this.cameras.main.setBounds(0, 0, Configer.GAME_MAP_WIDTH, Configer.GAME_MAP_HEIGHT);

        // let img = this.add.image(510, 350, 'mapmain');
        // let img2 = this.add.image(510, 350, 'mapmain');

        this.tian = this.add.container(200, 30, [
            this.add.image(1000, 0, 'once_tian').setScale(0.5, 0.5),
            this.add.image(500, 0, 'once_tian').setScale(0.5, 0.5),
            this.add.image(0, 0, 'once_tian').setScale(0.5, 0.5),
        ])

        this.tian.setScrollFactor(0);

        this.add.container(510, 350, [


            this.add.image(0, -200, 'one_grass').setScale(0.5, 0.5),
            this.add.image(1020, -200, 'one_grass').setScale(0.5, 0.5),
            this.add.image(2040, -200, 'one_grass').setScale(0.5, 0.5),



            this.add.image(0, 0, 'mapmain').setScale(0.5, 0.5),
            this.add.image(1020, 0, 'mapmain').setScale(0.5, 0.5),
            this.add.image(2040, 0, 'mapmain').setScale(0.5, 0.5),

            this.add.image(-400, -200, 'once_enclosure3').setScale(0.5, 0.5),
            this.add.image(-220, -190, 'once_enclosure2').setScale(0.5, 0.5),
            this.add.image(0, -190, 'once_enclosure4').setScale(0.5, 0.5),
            this.add.image(265, -191, 'once_enclosure1').setScale(0.5, 0.5),
            this.add.image(570, -190, 'once_enclosure4').setScale(0.5, 0.5),


            this.add.image(1900, -200, 'once_enclosure3').setScale(0.5, 0.5),
            this.add.image(2100, -190, 'once_enclosure2').setScale(0.5, 0.5),
            this.add.image(2305, -190, 'once_enclosure4').setScale(0.5, 0.5),
            this.add.image(2570, -191, 'once_enclosure1').setScale(0.5, 0.5),

            this.add.image(0, 220, 'one_ironfence').setScale(0.5, 0.5),
            this.add.image(1020, 220, 'one_ironfence').setScale(0.5, 0.5),
            this.add.image(2040, 220, 'one_ironfence').setScale(0.5, 0.5),
            this.add.image(1500, -200, 'one_lousycar').setScale(0.5, 0.5),

        ]);

        // img.scaleX = 0.5;
        // img.scaleY = 0.5;

        // let img = this.add.image(gameWidth / 2, gameHeight / 2, 'background');

        let ta1 = this.add.sprite(220, 320, 'cannon02');
        ta1.setScale(0.7, 0.7)
        ta1.scaleX = -0.7;
        // this.spine.scaleX = -0.4;


        let mh_1304 = this.add.spine(330, 320, 'mh_1304', 'holdon', true);


        // mh_1304.scaleX = 0.8


        // mh_1304.scaleX = 0.8
        // mh_1304.scaleY = 0.8
        console.log(mh_1304.width, mh_1304.height)
        // let mh_1303 = this.add.spine(330, 420, 'mh_1303', 'idle', true);

        // let mh_1017 = this.add.spine(450, 320, 'mh_1017', 'idle', true);
        // let mh_1310 = this.add.spine(450, 420, 'mh_1310', 'idle', true);

        // let mh_5006_3 = this.add.spine(430, 420, 'mh_5006_3', 'idle', true);
        // let mh_5006_2 = this.add.spine(430, 320, 'mh_5006_2','idle',true);
        // let mh_5011 = this.add.spine(530, 320, 'mh_5011','idle',true);

        // let mh_5014 = this.add.spine(630, 320, 'mh_5014','idle',true);
        // mh_5014.scaleX = 0.4
        // mh_5014.scaleY = 0.4
        
        
        // let mh_5056 = this.add.spine(630, 420, 'mh_5056','idle',true);
        // mh_5056.scaleX = 0.4
        // mh_5056.scaleY = 0.4


        this.playerMain = this.add.sprite(0, 0, 'cao');
        
        this.playerMain.scaleY = -1

                
        this.cameras.main.startFollow(this.playerMain, true, 1, 1, 0, 70);

        this.cursors = this.input.keyboard.createCursorKeys();

        // this.add.spine(400, 350, 'idle');
        // this.spine = this.scene.add.spine(400, 500, key, 'holdon', true);


        // cursors.up!.on('down', () => {
        //     playerMain.y -= 10;
        // });
        // cursors.down!.on('down', () => {
        //     playerMain.y += 10;
        // });
        // cursors.left!.on('down', () => {
        //     playerMain.x -= 10;
        // })
        // cursors.right!.on('down', () => {
        //     playerMain.x += 10;
        // });
        console.log('create')
    }

    update(time: number, delta: number): void {
        if (this.cursors.up!.isDown) {
            this.playerMain.y -= 1;
        } else if (this.cursors.down!.isDown) {
            this.playerMain.y += 1;
        } else if (this.cursors.left!.isDown) {
            this.playerMain.x -= 1;
            // this.tian.x -= ;
        } else if (this.cursors.right!.isDown) {
            this.playerMain.x += 1;
            // this.tian.x += 1;

        }

    }
}